package com.muyu.blog.controller;

import com.muyu.blog.common.aop.LogAnnotation;
import com.muyu.blog.entity.vo.params.PageParams;
import com.muyu.blog.entity.vo.Result;
import com.muyu.blog.service.ArticleService;
import com.muyu.blog.entity.vo.ArticleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "ArticleController",description = "文章")
@RestController
@RequestMapping("articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @ApiOperation("分页获取文章")
    @PostMapping
    public Result articles(@RequestBody PageParams pageParams){

        List<ArticleVo> articles = articleService.listArticlesPage(pageParams);

        return Result.success(articles);
    }

    @PostMapping("hot")
    public Result hotArticle(){
        int limit=5;
        return articleService.hotArticle(limit);
    }

    @PostMapping("new")
    public Result newArticles(){
        int limit=5;
        return articleService.newArticles(limit);
    }

    @PostMapping("listArchives")
    @LogAnnotation(module = "文章",operation = "获取文章列表")
    public Result listArchives(){
        return articleService.listArchives();
    }

    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long articleId){
        return articleService.findArticleById(articleId);
    }
}
